{% extends "nomcom/nomcom_private_base.html" %}
{# Copyright The IETF Trust 2015-2023, All Rights Reserved #}
{% load origin %}
{% load nomcom_tags textfilters %}
{% block subtitle %}- View feedback about {{ nominee.email.person.name }}{% endblock %}
{% block nomcom_content %}
{% origin %}
{% if reclassify_feedback %}
    {% include "nomcom/reclassify_feedback_item.html" %}
{% else %}
    <h2>Feedback about {{ nominee }}</h2>
    <ul class="nav nav-tabs my-3" role="tablist">
        {% for ft in feedback_types %}
            <li class="nav-item">
                <button class="nav-link {% if forloop.first %}active{% endif %}"
                        data-bs-target="#{{ ft.slug }}"
                        role="tab" type="button"
                        data-bs-toggle="tab">
                    {{ ft.name }}
                </button>
            </li>
        {% endfor %}
    </ul>
    <div class="tab-content">
        {% for ft in feedback_types %}
            <div role="tabpanel" class="tab-pane {% if forloop.first %} active{% endif %}"
                 id="{{ ft.slug }}">
                {% for feedback in nominee.feedback_set.all %}
                    {% if feedback.type.slug == ft.slug %}
                        <dl class="row">
                            <dt class="col-sm-2">
                                {% if feedback.time > last_seen_time %}<span class="badge rounded-pill text-bg-success">New</span>{% endif %}
                                From
                            </dt>
                            <dd class="col-sm-10">
                                {{ feedback.author|formatted_email|default:"Anonymous"|linkify }}
                                {% if ft.slug == "nomina" and feedback.nomination_set.first.share_nominator %}
                                    <span class="badge rounded-pill text-bg-info">OK to share name with nominee</span>
                                {% endif %}
                            </dd>
                            <dt class="col-sm-2">
                                Date
                            </dt>
                            <dd class="col-sm-10">
                                {{ feedback.time|date:"Y-m-d" }}
                            </dd>
                            {% if ft.slug == "nomina" %}
                                {% for fn in feedback.nomination_set.all %}
                                    {% if fn.candidate_name %}
                                        <dt class="col-sm-2">
                                            Nominee
                                        </dt>
                                        <dd class="col-sm-10">
                                            {{ fn.candidate_name }}
                                        </dd>
                                    {% endif %}
                                    {% if fn.candidate_phone %}
                                        <dt class="col-sm-2">
                                            Nominee phone
                                        </dt>
                                        <dd class="col-sm-10">
                                            {{ fn.candidate_phone }}
                                        </dd>
                                    {% endif %}
                                {% endfor %}
                            {% endif %}
                            <dt class="col-sm-2">
                                Positions
                            </dt>
                            <dd class="col-sm-10">
                                {{ feedback.positions.all|join:"," }}
                            </dd>
                            {% if feedback.subject %}
                                <dt class="col-sm-2">
                                    Subject
                                </dt>
                                <dd class="col-sm-10">
                                    {{ feedback.subject }}
                                </dd>
                            {% endif %}
                            <dt class="col-sm-2">
                                Feedback
                            </dt>
                            <dd class="col-sm-10 pasted">
                                <pre>{% decrypt feedback.comments request year 1 %}</pre>
                            </dd>
                            {% if user|is_chair_or_advisor:year %}
                            <dt class="col-sm-2">
                                <form id="reclassify-{{ feedback.id }}" method="post">
                                    {% csrf_token %}
                                    <input type="hidden" name="feedback_id" value="{{ feedback.id }}">
                                    {% if ft.slug == "questio" %}
                                    <p><button class="btn btn-warning btn-sm" type="submit" name="submit" value="download">
                                        Download
                                    </button></p>
                                    {% endif %}
                                    <button class="btn btn-warning btn-sm" type="submit" name="submit" value="reclassify">
                                        Reclassify
                                    </button>
                                </form>
                            </dt>
                            <dd>
                            </dd>
                            {% endif %}
                        </dl>
                        {% if not forloop.last %}<hr>{% endif %}
                    {% endif %}
                {% endfor %}
            </div>
        {% endfor %}
    </div>
    <a class="btn btn-secondary"
       href="{% url 'ietf.nomcom.views.view_feedback' year %}">Back</a>
{% endif %}
{% endblock %}
{% block js %}
    <script>
        $(document)
            .ready(function () {
                // Javascript to enable link to tab
                var url = document.location.toString();
                if (url.match('#')) {
                    $('.nav-tabs button[data-bs-target="#' + url.split('#')[1] + '"]')
                        .tab('show');
                }
                // Change hash for page-reload
                $('.nav-tabs button')
                    .on('shown.bs.tab', function (e) {
                        history.replaceState(null, null, e.currentTarget.dataset.bsTarget);
                    });
            });
    </script>
{% endblock %}
